from django_redis import get_redis_connection


class MyRedis:
    def __init__(self):
        self.redis=get_redis_connection("code")
    def setcode(self,phone,code):
        self.redis.setex(phone,120,code)
    def getcode(self,phone):
        code=self.redis.get(phone)
        if not code:
            return None
        return code.decode('utf-8')
    #设置热搜词
    def setword(self,word):
        self.redis.zincrby("hotword",1,word)
    def getword(self):
        return self.redis.zrevrange("hotword",0,5)
    def set_token_exp(self, token, seconds):
        """
        用token为key，剩余秒数为value存入redis
        """
        self.redis.set(token, seconds)

toolredis=MyRedis()